//
//  CarTableViewCell.m
//  UI10_homework(TableViewCellSelfSize)
//
//  Created by Hanlingyu on 16/7/27.
//  Copyright © 2016年 ltq. All rights reserved.
//

#import "CarTableViewCell.h"
#import "UIView+Frame.h"
#import "CarNewsObject.h"
#import "UIImageView+WebCache.h"
@interface CarTableViewCell ()

@property (nonatomic, strong) UIImageView *carImageView;
@property (nonatomic, strong) UILabel *carTitleLabel;

@end

@implementation CarTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}


- (void)createView {
    
    _carImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
//    _carImageView.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:_carImageView];
    
    _carTitleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
//    _carTitleLabel.backgroundColor = [UIColor blueColor];
    _carTitleLabel.numberOfLines = 0;
    [self.contentView addSubview:_carTitleLabel];

    
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    CGFloat leftSpace = 10;
    CGFloat topSpace = 10;
    CGFloat bottomSpace = 10;
    CGFloat middleSpace = 10;
    CGFloat carImageViewWidth = self.contentView.ltq_width / 4;
    CGFloat carImageViewHeight = self.contentView.ltq_height - topSpace - bottomSpace;
    _carImageView.frame = CGRectMake(leftSpace, topSpace, carImageViewWidth, carImageViewHeight);
    
    CGFloat carTitleLabelX = _carImageView.ltq_width + middleSpace;
    CGFloat carTitleLabelWidth = self.contentView.ltq_width - _carImageView.ltq_width - leftSpace - middleSpace;
    CGFloat carLabelHeight = self.contentView.ltq_height - topSpace - bottomSpace;

    _carTitleLabel.frame = CGRectMake(carTitleLabelX, topSpace, carTitleLabelWidth, carLabelHeight);
    
    
    
}

- (void)setCarNew:(CarNewsObject *)carNew {
    _carNew = carNew;
    _carTitleLabel.text = carNew.title;
    
    [_carImageView sd_setImageWithURL:[NSURL URLWithString:carNew.picCover]];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
